﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DesignPatterns.AdapterPatterns
{
    class AdapterPattern
    {
        static void Main(string[] args)
        {
            //适配器模式，设计好的投产项目，突然想切换成一个与现有系统没关系的类来运行，可以增加一个适配器，让新插进来的类可以适配现有系统
            //适配器的灵活性也不错，即插即用，不想要就删掉

            //原有业务逻辑
            ITarget target = new ConcreteTarget();
            target.request();
            //适配器逻辑
            ITarget target2 = new Adapter();
            target2.request();
        }
    }
    /// <summary>
    /// 目标抽象类
    /// </summary>
    public interface ITarget {
        void request();
    }
    /// <summary>
    /// 目标具体类
    /// </summary>
    public class ConcreteTarget : ITarget {
        public void request() {
            Console.WriteLine("Target Dosomething");
        }
    }
    /// <summary>
    /// 源角色类
    /// </summary>
    public class Adaptee {
        public void doSomething() {
            Console.WriteLine("I'm doing something");
        }
    }
    /// <summary>
    /// 适配器角色
    /// </summary>
    public class Adapter : Adaptee, ITarget {
        public void request() {
            base.doSomething();
        }
    }
}
